import {Injectable} from "@angular/core";
import {Http} from "@angular/http";
import {Hero} from "./hero";
import 'rxjs/add/operator/toPromise';
/**
 * Created by admin on 2017/1/5.
 */
@Injectable()
export class HeroService {
    private heroesUrl = '/angualjs/myherosdata.json';  // URL to web api
    constructor(private  http:Http){
    }
    getHeroes(): Promise<Hero[]> {
        return this.http.get(this.heroesUrl).toPromise().then(response=>response.json().data as Hero[]).catch(this.handleError);
    }
    private handleError(error: any): Promise<any> {
        console.error('An error occurred', error); // for demo purposes only
        return Promise.reject(error.message || error);
    }

}